﻿using GrainManage.Data.Model;
using GrainManage.Entities.Type;
using GrainManage.Proxy;
using GrainManage.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace GrainManage.Web.Controllers
{
    public class TypeController : BaseController
    {
        public ActionResult GetTradeType(PageModel page)
        {
            return RedirectToAction("GetPriceType", "Type", page);
        }

        public ActionResult GetPriceType(PageModel page)
        {
            var inputPara = new InputGetNameByFlag
            {
                Authentication = CurrentAccount,
                PageIndex = page.pageIndex,
                PageSize = page.pageSize,
                Flag = TypeFlag.Default
            };
            var typeProxy = ObjectFactory.TypeProxy;
            var output = typeProxy.GetNameByFlag(inputPara);
            if (Request.IsAjaxRequest())
            {
                return NewtonsoftJson(output.Types);
            }
            else
            {
                return PartialView(Constant.DropDownListView, output.Types);
            }
        }

        [HttpPost]
        public ActionResult GetGrainType(PageModel page)
        {
            var inputPara = new InputGetNameByFlag
            {
                Authentication = CurrentAccount,
                PageIndex = page.pageIndex,
                PageSize = page.pageSize,
                Flag = TypeFlag.Grain
            };
            var typeProxy = ObjectFactory.TypeProxy;
            var output = typeProxy.GetNameByFlag(inputPara);
            if (Request.IsAjaxRequest())
            {
                return NewtonsoftJson(output.Types);
            }
            else
            {
                return PartialView(Constant.DropDownListView, output.Types);
            }
        }

    }
}
